<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>20-vue父组件refs获取子组件</title>
</head>
<body>
  <div id="app">
    <cpn1 ref="aaa"></cpn1>
    <button @click="buttonClick">按钮</button>
  </div>

  <template id="cpn1">
    <div>
      <p>我是子组件</p>
    </div>
  </template>

  <script src="./js/vue.js"></script>
  <script>
    const app = new Vue({
      el: "#app",
      methods: {
        buttonClick() {
          let cpn1 = this.$refs["aaa"]; // 通过 this.$refs 获取子组件
          console.log(cpn1.name);
        }
      },
      components: {
        cpn1: {
          template: "#cpn1",
          data() {
            return {
              name: "子组件name"
            }
          }
        }
      }
    })
  </script>
</body>
</html>